#include"Shared.hpp"

int main()
{
    key_t k = getkey();
    printf("0x%x\n",k);
    int shmid = getshm(k);//接收共享内存
    printf("shmid : %d\n", shmid);

    char* p = (char*)attachshm(shmid);//关联
    printf("attach sucess, address p: %p\n",p);

    //使用
    const char* str = "hello server, i am process A，我在和你通信";
    pid_t id = getpid();
    int count = 0;
    
    while(count<10)
    {
        sleep(1);
        snprintf(p, MAX_SIZE, "%S[pid:%d][消息编号:%d]", str, id, count++);
    }

    detachshm(p);//去关联

    return 0;
}
